<template>
	<view>
		<u-subsection :list="[{name:'未完成任务'},{name:'已完成任务'}]" @change="change" :current="current" ></u-subsection>
		<u-empty v-if="!myTaskList" style="margin-top: 60%;"  text="暂时无任务"  mode="list"></u-empty>
		<u-cell-group>
			<view v-for="(item,index) in  myTaskList" :key="item.taskTeacherId" >
				<u-cell-item v-if="!item.isComplete && current==0"  @click="gotoTaskNews(item.taskTeacherId)" :title="'任务名称：'+item.taskDO.taskName">
					<view slot="label">
						<p>任务类型：{{item.taskDO.taskTypeId}}</p>
					</view>
				</u-cell-item>
				<u-cell-item v-if="item.isComplete && current==1"  @click="gotoTaskNews(item.taskTeacherId)" :title="'任务名称：'+item.taskDO.taskName">
					<view slot="label">
						<p>任务类型：{{item.taskDO.taskTypeId}}</p>
					</view>
				</u-cell-item>
			</view>
		</u-cell-group>
		<u-empty v-if="myTaskList && myTaskList.filter(f=>!f.isComplete).length ==0 && current==0" style="margin-top: 60%;"  text="暂时无未完成任务"  mode="list"></u-empty>
		<u-empty v-if="myTaskList && myTaskList.filter(f=>f.isComplete).length == 0 && current==1" style="margin-top: 60%;"  text="暂时无已完成任务"  mode="list"></u-empty>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				current:0
			}
		},
		methods: {
			getAllUserIsAcceptTask(){
				this.$u.http.get(`/task/getAllUserIsAcceptTask/${this.user.userId}`).then(res=>{
					if(res.data){
						this.$store.commit("myTaskList",res.data)
					}
				})
			},
			gotoTaskNews(taskTeacherId){
				this.$u.route({ url:"pages/task/taskInfo",params:{
					"taskTeacherId":taskTeacherId
				}})
			},
			change(val){
				this.current = val
			}
		},
		computed:{
			user(){
				return this.$store.state.user
			},
			myTaskList(){
				return this.$store.state.myTaskList
			}
		},
		created() {
			this.getAllUserIsAcceptTask()
		}
	}
</script>

<style scoped="scss">

</style>
